import {message} from "ant-design-vue";
import {token, user} from '~/logic/storage'
import RenderOption from "~/utils/render/renderOption";

export * from './storage'
export * as Api from './api'
export * as UserApi from './apis/user'
export * as ToolApi from './apis/tool'

export function isLogin(context: { emit: any }, option: RenderOption): boolean {
    console.log(user.value,token.value);
    if (token.value === '' || typeof user.value === 'undefined' || !user.value) {
        // if (typeof context.emit !== 'undefined')
        context.emit('login')
        // else
        return false
    } else {
        if (option && typeof option.platformAuth !== 'undefined') {
            const projects: any = user.value.project;
            if (!Object.keys(projects).includes(option.platformAuth)) {
                window.dispatchEvent(new Event('SYCM_SHOW_USER'));
                message.warning('您暂无使用权限，请购买后使用！');
                return false
            } else {
                // HH-MM-DD HH:ii:ss
                const expireTime = projects[option.platformAuth].expire_time;
                // 判断expireTime是否大于当前日期
                const now = new Date();
                const expire = new Date(expireTime);
                if (expire.getTime() < now.getTime()) {
                    window.dispatchEvent(new Event('SYCM_SHOW_USER'));
                    message.warning('您的使用权限已过期，请续费后使用！');
                    return false
                }
            }
        }
    }
    return true
}
